package com.limeng.sys.controller;

import com.limeng.common.Result;
import com.limeng.sys.entity.Dongman;
import com.limeng.sys.entity.Role;
import com.limeng.sys.service.IDongmanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author limeng
 * @since 2023-03-27
 */
@RestController
@RequestMapping("/dongman")
public class DongmanController {
    @Autowired
    private IDongmanService dongmanService;
    /**
     * 查询所有
     * @return
     */
    @GetMapping("/all")
    public Result<List<Dongman>> getAll(){
        List<Dongman> list = dongmanService.list();
        return Result.success(list);
    }

    /**
     * 新增动漫接口
     * @param dongman
     * @return
     */
    @PostMapping
    public Result<?> addDongman(@RequestBody Dongman dongman){
        dongmanService.save(dongman);
        return Result.success("新增动漫成功");
    }

    /**
     * 修改动漫接口
     * @param dongman
     * @return
     */
    @PutMapping
    public Result<?> updateDongman(@RequestBody Dongman dongman){
        dongmanService.updateById(dongman);
        return Result.success("修改动漫成功");
    }

    /**
     * 删除动漫
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result<?> deleteRoleById(@PathVariable("id") Integer id){
        dongmanService.removeById(id);
        return Result.success("删除动漫成功");
    }

    /**
     * 动漫信息回显
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<Dongman> getDongmanById(@PathVariable("id") Integer id){
        Dongman dongman = dongmanService.getById(id);
        return Result.success(dongman);
    }

}
